package R.Service;

import R.Dao.DoctorDao;
import R.Dao.SickDao;
import R.Entity.Diagnosis;
import R.Entity.Doctor;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DoctorShowAllServlet", value = "/Doctor")
public class DoctorShowAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        List<Doctor> list = DoctorDao.showAll();
        if (list != null) {
            request.setAttribute("DoctorList", list);//在请求过程中绑定
            request.getRequestDispatcher("/R/doctor.jsp").forward(request, response);//请求转发
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        /*HttpSession session = request.getSession();
        if (session.getAttribute("loginName")==null){
            response.sendRedirect("/Test/dormLogin.jsp");
        }*/
        String department_name = request.getParameter("department_name");//科室名称
        String doctor_name = request.getParameter("doctor_name");//医生姓名
        //创建实体类
        Doctor d = new Doctor();
        d.setDepartment_name(department_name);
        d.setDoctor_name(doctor_name);
        if (!department_name.equals("") && !doctor_name.equals("")) {
            List<Doctor> list = DoctorDao.ChaXun(d);
            if (list != null) {
                request.setAttribute("DoctorList", list);//在请求过程中绑定
                request.getRequestDispatcher("/R/doctor.jsp").forward(request, response);//请求转发
            }
        } else {
            List<Doctor> list = DoctorDao.showAll();
            if (list != null) {
                request.setAttribute("DoctorList", list);//在请求过程中绑定
                request.getRequestDispatcher("/R/doctor.jsp").forward(request, response);//请求转发
            }
        }
    }
}
